package com.eqdd.yiqidian.base.loading.waitdialog;


import android.content.Context;
import android.util.Log;

import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.base.loading.INetLoadingView;

import io.reactivex.android.schedulers.AndroidSchedulers;


public class DialogHelper implements INetLoadingView {


    private WaitDialog dialog;

    public DialogHelper(Context context) {
        dialog = null;
        try {
            dialog = new WaitDialog(context, R.style.CDialog);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @Override
    public void showLoading() {
        try {
            if (!dialog.isShowing()) {
                dialog.show();
            }
        } catch (Exception e) {
            Log.i("yiqidain", "dialog show error");
        }
    }

    @Override
    public void showLoading(final String msg) {
        AndroidSchedulers.mainThread().createWorker().schedule(() -> {
            try {
                if (!dialog.isShowing()) {
                    dialog.setMessage(msg);
                    dialog.show();
                }
            } catch (Exception e) {
                Log.i("yiqidain", "dialog show error");
            }
        });
    }

    @Override
    public void hideLoading(String msg) {
        dialog.dismiss();
    }

    @Override
    public void hideLoading() {
        try {
            if (dialog.isShowing()){
                dialog.dismiss();
            }
        } catch (Exception e) {
            Log.i("yiqidain", "dialog dismiss error");
        }
    }

}
